var listData = {};
$.ajax({
    url: `https://api.zhihuifangdong.net/admin/pNews/getOneNews?id=${getUrlParam('id')?getUrlParam('id'):'1'}`, success: function (result) {
        console.log(result.data);
        listData = result.data.data;
        listData.reverse();
        listData.forEach((item,index)=>{
            if (getUrlParam('id').toString()===item.id.toString()){
                document.getElementById('details-title').innerHTML = listData[index].title;
                document.getElementById('gmtCreate').innerHTML = listData[index].gmtCreate;
                document.getElementById('mainText').innerHTML = listData[index].content;
            }
        })
        // document.getElementById('details-title').innerHTML = result.data.data[1].title;
        // document.getElementById('gmtCreate').innerHTML = result.data.data[1].gmtCreate;
        // document.getElementById('mainText').innerHTML = result.data.data[1].content;
    }
});

//返回上一页
function returnPage(){

}

function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return decodeURIComponent(r[2]);
    }
    return '';
}
function turnPage(turn){
    let id;
    if (turn){
        if (getUrlParam('id')===listData[listData.length-1].id.toString()){
            alert('已经是最后一篇了');
            return;
        }else if(getUrlParam('id')===listData[0].id.toString()){
            id = listData[1].id;
        }else{
            id = listData[2].id;
        }
    }else{
        if (getUrlParam('id')===listData[0].id.toString()){
            alert('已经是第一篇了');
            return;
        }
        id = listData[0].id;
    }
    location.replace("news-details.html?id=" + id);
}
